
local crows_num = 7
-------- 以reward low 为基准
local trades_list = {
	["Equipments"] = {	----- 1 号售卖  装备为主
		{  wanted = "goldnugget", wanted_num = 30, ret = "orangestaff", ret_num = 1, },	-- 橙色 - 传送法杖
		{  wanted = "goldnugget", wanted_num = 30, ret = "yellowstaff", ret_num = 1, },	-- 黄色 - 唤星法杖
		{  wanted = "goldnugget", wanted_num = 30, ret = "greenstaff", ret_num = 1, },	-- 绿色 - 分解法杖
		{  wanted = "goldnugget", wanted_num = 10, ret = "icestaff", ret_num = 1, },	-- 蓝色 - 冰冻法杖
		{  wanted = "goldnugget", wanted_num = 10, ret = "firestaff", ret_num = 1, },	-- 红色 - 火法杖
		{  wanted = "goldnugget", wanted_num = 15, ret = "telestaff", ret_num = 1, },	-- 紫色 - 传送法杖
		{  wanted = "npc_item_goldnugget_coin", wanted_num = 3, ret = "opalstaff", ret_num = 1, },	-- 唤月法杖
		{  wanted = "goldnugget", wanted_num = 5, ret = "firepen", ret_num = 1, },	-- 火焰笔
		{  wanted = "goldnugget", wanted_num = 5, ret = "cane", ret_num = 1, },	-- 步行手杖
		{  wanted = "goldnugget", wanted_num = 2, ret = "bullkelp_root", ret_num = 1, },	-- 海带鞭子
		{  wanted = "goldnugget", wanted_num = 5, ret = "whip", ret_num = 1, },	-- 猫尾鞭子
		{  wanted = "goldnugget", wanted_num = 1, ret = "spear", ret_num = 1, },	-- 长矛
		{  wanted = "goldnugget", wanted_num = 1, ret = "fence_rotator", ret_num = 1, },	-- 栅栏击剑
		{  wanted = "goldnugget", wanted_num = 4, ret = "spear_wathgrithr", ret_num = 1, },	-- 战斗长矛
		{  wanted = "goldnugget", wanted_num = 15, ret = "batbat", ret_num = 1, },	-- 蝙蝠棒
		{  wanted = "npc_item_goldnugget_coin", wanted_num = 1, ret = "trident", ret_num = 1, },	-- 三叉戟
		{  wanted = "goldnugget", wanted_num = 30, ret = "ruins_bat", ret_num = 1, },	-- 铥矿棒
		{  wanted = "goldnugget", wanted_num = 30, ret = "glasscutter", ret_num = 1, },	-- 玻璃刀
		{  wanted = "goldnugget", wanted_num = 25, ret = "nightstick", ret_num = 1, },	-- 晨星锤
		{  wanted = "goldnugget", wanted_num = 25, ret = "shieldofterror", ret_num = 1, },	-- 恐怖盾牌
		{  wanted = "goldnugget", wanted_num = 1, ret = "blowdart_pipe", ret_num = 1, },	-- 普通吹箭
		{  wanted = "goldnugget", wanted_num = 1, ret = "blowdart_yellow", ret_num = 1, },	-- 雷电吹箭
		{  wanted = "goldnugget", wanted_num = 1, ret = "blowdart_sleep", ret_num = 1, },	-- 催眠吹箭
		{  wanted = "goldnugget", wanted_num = 1, ret = "blowdart_fire", ret_num = 1, },	-- 火吹箭
		{  wanted = "goldnugget", wanted_num = 30, ret = "thurible", ret_num = 1, },	-- 暗影香炉
		{  wanted = "goldnugget", wanted_num = 5, ret = "umbrella", ret_num = 1, },	-- 雨伞
		{  wanted = "goldnugget", wanted_num = 1, ret = "grass_umbrella", ret_num = 1, },	-- 花伞
		{  wanted = "goldnugget", wanted_num = 5, ret = "lantern", ret_num = 1, },	-- 提灯
		{  wanted = "goldnugget", wanted_num = 30, ret = "multitool_axe_pickaxe", ret_num = 1, },	-- 多用斧头
		{  wanted = "goldnugget", wanted_num = 30, ret = "moonglassaxe", ret_num = 1, },	-- 玻璃斧头
		{  wanted = "goldnugget", wanted_num = 50, ret = "malbatross_beak", ret_num = 1, },	-- 邪天翁喙
		{  wanted = "goldnugget", wanted_num = 2, ret = "oar_driftwood", ret_num = 1, },	-- 浮木浆
		{  wanted = "goldnugget", wanted_num = 2, ret = "bugnet", ret_num = 1, },	-- 虫网
		{  wanted = "goldnugget", wanted_num = 10, ret = "fishingnet", ret_num = 1, },	-- 渔网
		{  wanted = "goldnugget", wanted_num = 15, ret = "minerhat", ret_num = 1, },	-- 矿工帽
		{  wanted = "goldnugget", wanted_num = 15, ret = "molehat", ret_num = 1, },	-- 鼹鼠帽
		{  wanted = "goldnugget", wanted_num = 15, ret = "cookiecutterhat", ret_num = 1, },	-- 饼干切割机帽
		{  wanted = "goldnugget", wanted_num = 15, ret = "footballhat", ret_num = 1, },	-- 橄榄帽
		{  wanted = "goldnugget", wanted_num = 5, ret = "wathgrithrhat", ret_num = 1, },	-- 女武神战斗帽
		{  wanted = "goldnugget", wanted_num = 5, ret = "beehat", ret_num = 1, },	-- 养蜂帽
		{  wanted = "goldnugget", wanted_num = 30, ret = "ruinshat", ret_num = 1, },	-- 铥矿帽
		{  wanted = "goldnugget", wanted_num = 40, ret = "hivehat", ret_num = 1, },	-- 蜂王皇冠
		{  wanted = "goldnugget", wanted_num = 30, ret = "skeletonhat", ret_num = 1, },	-- 骨头帽
		{  wanted = "npc_item_goldnugget_coin", wanted_num = 5, ret = "alterguardianhat", ret_num = 1, },	-- 启迪皇冠
		{  wanted = "goldnugget", wanted_num = 30, ret = "armorruins", ret_num = 1, },	-- 铥矿盔甲
		{  wanted = "goldnugget", wanted_num = 25, ret = "armor_sanity", ret_num = 1, },	-- 暗影盔甲
		{  wanted = "goldnugget", wanted_num = 15, ret = "armormarble", ret_num = 1, },	-- 大理石盔甲
		{  wanted = "goldnugget", wanted_num = 25, ret = "armordragonfly", ret_num = 1, },	-- 鳞甲
		{  wanted = "goldnugget", wanted_num = 35, ret = "armorskeleton", ret_num = 1, },	-- 骨头盔甲
		{  wanted = "npc_item_goldnugget_coin", wanted_num = 3, ret = "krampus_sack", ret_num = 1, },	-- 坎普斯背包
		{  wanted = "goldnugget", wanted_num = 15, ret = "icepack", ret_num = 1, },	-- 保鲜背包
		{  wanted = "goldnugget", wanted_num = 15, ret = "seedpouch", ret_num = 1, },	-- 种子袋
		{  wanted = "npc_item_goldnugget_coin", wanted_num = 2, ret = "polly_rogershat", ret_num = 1, },	-- 鹦鹉帽
		{  wanted = "goldnugget", wanted_num = 2, ret = "kelphat", ret_num = 1, },	-- 海花环
		{  wanted = "goldnugget", wanted_num = 10, ret = "featherhat", ret_num = 1, },	-- 羽毛帽
		{  wanted = "goldnugget", wanted_num = 10, ret = "tophat", ret_num = 1, },	-- 高礼帽
		{  wanted = "goldnugget", wanted_num = 30, ret = "moonstorm_goggleshat", ret_num = 1, },	-- 星象护目镜
		{  wanted = "goldnugget", wanted_num = 5, ret = "catcoonhat", ret_num = 1, },	-- 猫帽
		{  wanted = "goldnugget", wanted_num = 2, ret = "earmuffshat", ret_num = 1, },	-- 兔耳帽
		{  wanted = "goldnugget", wanted_num = 5, ret = "winterhat", ret_num = 1, },	-- 冬帽
		{  wanted = "goldnugget", wanted_num = 5, ret = "walrushat", ret_num = 1, },	-- 贝雷帽
		{  wanted = "goldnugget", wanted_num = 5, ret = "beefalohat", ret_num = 1, },	-- 牛帽
		{  wanted = "goldnugget", wanted_num = 20, ret = "red_mushroomhat", ret_num = 1, },	-- 红蘑菇帽
		{  wanted = "goldnugget", wanted_num = 20, ret = "blue_mushroomhat", ret_num = 1, },	-- 蓝蘑菇帽
		{  wanted = "goldnugget", wanted_num = 20, ret = "green_mushroomhat", ret_num = 1, },	-- 绿蘑菇帽
		{  wanted = "goldnugget", wanted_num = 10, ret = "watermelonhat", ret_num = 1, },	-- 西瓜帽
		{  wanted = "goldnugget", wanted_num = 10, ret = "icehat", ret_num = 1, },	-- 冰帽
		{  wanted = "goldnugget", wanted_num = 10, ret = "rainhat", ret_num = 1, },	-- 雨帽
		{  wanted = "goldnugget", wanted_num = 20, ret = "eyebrellahat", ret_num = 1, },	-- 眼球伞
		{  wanted = "goldnugget", wanted_num = 20, ret = "batnosehat", ret_num = 1, },	-- 牛奶帽
		{  wanted = "goldnugget", wanted_num = 40, ret = "nutrientsgoggleshat", ret_num = 1, },	-- 耕作先驱帽
		{  wanted = "goldnugget", wanted_num = 15, ret = "trunkvest_summer", ret_num = 1, },	-- 透气背心
		{  wanted = "goldnugget", wanted_num = 20, ret = "raincoat", ret_num = 1, },	-- 雨衣
		{  wanted = "goldnugget", wanted_num = 10, ret = "sweatervest", ret_num = 1, },	-- 犬牙背心
		{  wanted = "goldnugget", wanted_num = 10, ret = "trunkvest_winter", ret_num = 1, },	-- 冬季象鼻背心
		{  wanted = "goldnugget", wanted_num = 30, ret = "beargervest", ret_num = 1, },	-- 熊皮衣
		{  wanted = "goldnugget", wanted_num = 10, ret = "reflectivevest", ret_num = 1, },	-- 清凉夏装
		{  wanted = "goldnugget", wanted_num = 2, ret = "hawaiianshirt", ret_num = 1, },	-- 花衬衫
		{  wanted = "goldnugget", wanted_num = 25, ret = "antlionhat", ret_num = 1, },	-- 刮地头盔
		{  wanted = "goldnugget", wanted_num = 15, ret = "armor_bramble", ret_num = 1, },	-- 荆棘盔甲
		{  wanted = "goldnugget", wanted_num = 20, ret = "staff_tornado", ret_num = 1, },	-- 天气风向标
	},
	["Materials"] = {
		{  wanted = "goldnugget", wanted_num = 10, ret = "walrus_tusk", ret_num = 1, },	-- 海象牙
		{  wanted = "goldnugget", wanted_num = 30, ret = "gnarwail_horn", ret_num = 1, },	-- 独角鲸的角
		{  wanted = "goldnugget", wanted_num = 2, ret = "redgem", ret_num = 1, },	-- 红宝石
		{  wanted = "goldnugget", wanted_num = 5, ret = "orangegem", ret_num = 1, },	-- 橙色宝石
		{  wanted = "goldnugget", wanted_num = 5, ret = "yellowgem", ret_num = 1, },	-- 黄色宝石
		{  wanted = "goldnugget", wanted_num = 5, ret = "greengem", ret_num = 1, },	-- 绿色宝石
		{  wanted = "goldnugget", wanted_num = 2, ret = "bluegem", ret_num = 1, },	-- 蓝色宝石
		{  wanted = "goldnugget", wanted_num = 4, ret = "purplegem", ret_num = 1, },	-- 紫色宝石
		{  wanted = "goldnugget", wanted_num = 70, ret = "opalpreciousgem", ret_num = 1, },	-- 多彩宝石
		{  wanted = "goldnugget", wanted_num = 1, ret = "cutgrass", ret_num = 2, },	-- 草
		{  wanted = "goldnugget", wanted_num = 1, ret = "twigs", ret_num = 2, },	-- 树枝
		{  wanted = "goldnugget", wanted_num = 1, ret = "log", ret_num = 2, },	-- ，木头
		{  wanted = "goldnugget", wanted_num = 1, ret = "driftwood_log", ret_num = 2, },	-- ，浮木
		{  wanted = "goldnugget", wanted_num = 1, ret = "livinglog", ret_num = 2, },	-- 活木
		{  wanted = "goldnugget", wanted_num = 1, ret = "charcoal", ret_num = 5, },	-- 木炭
		{  wanted = "goldnugget", wanted_num = 1, ret = "cutreeds", ret_num = 3, },	-- 芦苇
		{  wanted = "goldnugget", wanted_num = 1, ret = "lightbulb", ret_num = 3, },	-- 荧光果
		{  wanted = "goldnugget", wanted_num = 3, ret = "nightmarefuel", ret_num = 2, },	-- 噩梦燃料
		{  wanted = "goldnugget", wanted_num = 2, ret = "boards", ret_num = 1, },	-- 木板
		{  wanted = "goldnugget", wanted_num = 1, ret = "papyrus", ret_num = 1, },	-- 草沙纸
		{  wanted = "goldnugget", wanted_num = 3, ret = "waxpaper", ret_num = 1, },	-- 蜡纸
		{  wanted = "goldnugget", wanted_num = 1, ret = "rocks", ret_num = 2, },	-- 石头
		{  wanted = "goldnugget", wanted_num = 1, ret = "flint", ret_num = 2, },	-- 燧石
		{  wanted = "goldnugget", wanted_num = 1, ret = "nitre", ret_num = 2, },	-- 硝石
		{  wanted = "goldnugget", wanted_num = 2, ret = "marble", ret_num = 1, },	-- 大理石
		{  wanted = "goldnugget", wanted_num = 5, ret = "moonrocknugget", ret_num = 1, },	-- 月岩
		{  wanted = "goldnugget", wanted_num = 3, ret = "thulecite_pieces", ret_num = 1, },	-- 铥矿碎片
		{  wanted = "goldnugget", wanted_num = 2, ret = "gears", ret_num = 1, },	-- 齿轮
		{  wanted = "goldnugget", wanted_num = 2, ret = "saltrock", ret_num = 1, },	-- 盐晶
		{  wanted = "goldnugget", wanted_num = 1, ret = "palmcone_scale", ret_num = 1, },	-- 棕榈树松果树鳞片
		{  wanted = "goldnugget", wanted_num = 1, ret = "moonglass", ret_num = 1, },	-- 月亮碎片
		{  wanted = "goldnugget", wanted_num = 2, ret = "fossil_piece", ret_num = 1, },	-- 化石碎片
		{  wanted = "goldnugget", wanted_num = 3, ret = "lightninggoathorn", ret_num = 1, },	-- 羊角
		{  wanted = "goldnugget", wanted_num = 1, ret = "boneshard", ret_num = 2, },	-- 骨头碎片
		{  wanted = "goldnugget", wanted_num = 1, ret = "slurtle_shellpieces", ret_num = 3, },	-- 贝壳碎片
		{  wanted = "goldnugget", wanted_num = 1, ret = "cookiecuttershell", ret_num = 1, },	-- 饼干切割机碎片
		{  wanted = "goldnugget", wanted_num = 20, ret = "bearger_fur", ret_num = 1, },	-- 熊皮
		{  wanted = "goldnugget", wanted_num = 20, ret = "dragon_scales", ret_num = 1, },	-- 龙蝇鳞片
		{  wanted = "goldnugget", wanted_num = 20, ret = "shroom_skin", ret_num = 1, },	-- 蘑菇鳞片
		{  wanted = "goldnugget", wanted_num = 20, ret = "deerclops_eyeball", ret_num = 1, },	-- 巨鹿眼球
		{  wanted = "goldnugget", wanted_num = 20, ret = "deerclops_eyeball", ret_num = 1, },	-- 巨鹿眼球
		{  wanted = "goldnugget", wanted_num = 1, ret = "pigskin", ret_num = 1, },	-- 猪皮
		{  wanted = "goldnugget", wanted_num = 10, ret = "goose_feather", ret_num = 1, },	-- 巨鹿鹅羽毛
		{  wanted = "goldnugget", wanted_num = 1, ret = "beefalowool", ret_num = 1, },	-- 牛毛
		{  wanted = "goldnugget", wanted_num = 10, ret = "steelwool", ret_num = 1, },	-- 钢丝棉
		{  wanted = "goldnugget", wanted_num = 2, ret = "honeycomb", ret_num = 1, },	-- 蜂巢
		{  wanted = "goldnugget", wanted_num = 1, ret = "silk", ret_num = 1, },	-- 蜘蛛丝
		{  wanted = "goldnugget", wanted_num = 10, ret = "mandrake", ret_num = 1, },	-- 曼德拉草
		{  wanted = "goldnugget", wanted_num = 1, ret = "gunpowder", ret_num = 1, },	-- 火药
		{  wanted = "goldnugget", wanted_num = 60, ret = "eyeturret_item", ret_num = 1, },	-- 眼睛炮台
		{  wanted = "goldnugget", wanted_num = 10, ret = "panflute", ret_num = 1, },	-- 排箫
		{  wanted = "goldnugget", wanted_num = 5, ret = "bandage", ret_num = 1, },	-- 蜂蜜膏药
		{  wanted = "goldnugget", wanted_num = 50, ret = "shadowheart", ret_num = 1, },	-- 暗影心房
		{  wanted = "goldnugget", wanted_num = 2, ret = "bundlewrap", ret_num = 1, },	-- 捆绑包装
		{  wanted = "goldnugget", wanted_num = 1, ret = "giftwrap", ret_num = 1, },	-- 礼物包装
		{  wanted = "goldnugget", wanted_num = 1, ret = "sewing_tape", ret_num = 1, },	-- 胶布
		{  wanted = "goldnugget", wanted_num = 1, ret = "bee", ret_num = 1, },	-- 蜜蜂
		{  wanted = "goldnugget", wanted_num = 1, ret = "killerbee", ret_num = 1, },	-- 杀人蜂
		{  wanted = "goldnugget", wanted_num = 2, ret = "fireflies", ret_num = 1, },	-- 萤火虫
		{  wanted = "goldnugget", wanted_num = 2, ret = "lightflier", ret_num = 1, },	-- 球光萤火虫
	},
	["Agriculture"] = {
		{  wanted = "goldnugget", wanted_num = 1, ret = "asparagus_seeds", ret_num = 2, },	-- 芦笋种
		{  wanted = "goldnugget", wanted_num = 1, ret = "carrot_seeds", ret_num = 2, },	-- 萝卜种
		{  wanted = "goldnugget", wanted_num = 1, ret = "corn_seeds", ret_num = 2, },	-- 玉米种
		{  wanted = "goldnugget", wanted_num = 1, ret = "eggplant_seeds", ret_num = 2, },	-- 茄子种子
		{  wanted = "goldnugget", wanted_num = 1, ret = "garlic_seeds", ret_num = 2, },	-- 蒜种
		{  wanted = "goldnugget", wanted_num = 1, ret = "onion_seeds", ret_num = 2, },	-- 洋葱种
		{  wanted = "goldnugget", wanted_num = 1, ret = "pepper_seeds", ret_num = 2, },	-- 辣椒种
		{  wanted = "goldnugget", wanted_num = 1, ret = "potato_seeds", ret_num = 2, },	-- 土豆种
		{  wanted = "goldnugget", wanted_num = 1, ret = "pumpkin_seeds", ret_num = 2, },	-- 南瓜
		{  wanted = "goldnugget", wanted_num = 1, ret = "tomato_seeds", ret_num = 2, },	-- 番茄种
		{  wanted = "goldnugget", wanted_num = 1, ret = "dragonfruit_seeds", ret_num = 2, },	-- 火龙果种
		{  wanted = "goldnugget", wanted_num = 1, ret = "durian_seeds", ret_num = 2, },	-- 榴莲种
		{  wanted = "goldnugget", wanted_num = 1, ret = "pomegranate_seeds", ret_num = 2, },	-- 石榴种
		{  wanted = "goldnugget", wanted_num = 1, ret = "watermelon_seeds", ret_num = 2, },	-- 石榴种
		{  wanted = "goldnugget", wanted_num = 10, ret = "dug_rock_avocado_bush", ret_num = 1, },	-- 石果灌木
		{  wanted = "goldnugget", wanted_num = 1, ret = "waterplant_planter", ret_num = 1, },	-- 海牙插穗芽
		{  wanted = "goldnugget", wanted_num = 3, ret = "dug_trap_starfish", ret_num = 1, },	-- 海星陷阱
		{  wanted = "goldnugget", wanted_num = 2, ret = "dug_monkeytail", ret_num = 1, },	-- 猴尾草
		{  wanted = "goldnugget", wanted_num = 10, ret = "palmcone_seed", ret_num = 1, },	-- 棕榈果树芽
		{  wanted = "goldnugget", wanted_num = 5, ret = "treegrowthsolution", ret_num = 1, },	-- 树浆果
		{  wanted = "goldnugget", wanted_num = 2, ret = "compost", ret_num = 1, },	-- 堆肥
	},

}



local function GetTradeData(inst,num)
	-- inst.__crow_trade_list

	if num == 1 then	--------- 装备1个
		local ret_table = inst.npc_base_lib:GetRandom(trades_list.Equipments)	--- 装备
		ret_table.wanted_image = ret_table.wanted
		ret_table.ret_image = ret_table.ret
		if TUNING.NPC_CONFIG.REWARDS_LESS == true then
			return ret_table
		else
			ret_table.wanted_num = math.ceil(ret_table.wanted_num *2/3 ) -- 向上取整
			return ret_table
		end
	elseif num == 2 then ------------- 农业1个
		local ret_table = inst.npc_base_lib:GetRandom(trades_list.Agriculture) ----农业
		ret_table.wanted_image = ret_table.wanted
		ret_table.ret_image = ret_table.ret
		if TUNING.NPC_CONFIG.REWARDS_LESS == true then
			return ret_table
		else
			ret_table.ret_num = math.ceil(ret_table.ret_num *2 ) -- 向上取整
			return ret_table
		end
	else	-------- 剩下的是材料
		local temp_Material_table= nil
		for i = 1, 300, 1 do
			local ret_table = inst.npc_base_lib:GetRandom(trades_list.Materials)
			if inst.__crow_trade_list[tostring(ret_table.ret)] ~= true then
				temp_Material_table = ret_table
				inst.__crow_trade_list[tostring(ret_table.ret)] = true
				break
			end			
		end

		if temp_Material_table == nil then
			return { wanted_image = "goldnugget",wanted_num = 1,ret_image = "log",ret_num = 12,}
		end
		temp_Material_table.wanted_image = temp_Material_table.wanted
		temp_Material_table.ret_image = temp_Material_table.ret

		if TUNING.NPC_CONFIG.REWARDS_LESS == true then
			return temp_Material_table
		else
			temp_Material_table.ret_num = temp_Material_table.ret_num * 2
			return temp_Material_table
		end
	end
end
local function Create_single_crow(pt,trade_data)
	-- local npc = SpawnPrefab("monster_npc_crowkid_trader")
    -- npc:PushEvent("Set",{
    --     pt = Vector3(x+5,y,z),
    --     trade_data = { 
    --         -- wanted_image = "goldnugget",
    --         wanted_image = "log",
    --         wanted_num = 40,
    --         ret_image = "moonglass",
    --         ret_num = 20,
    --         sound_off = true,
	--			block = true,	--- 屏蔽交易
    --     }
    -- })
    -- npc.Ready = true
	if TUNING.NPC_CONFIG.CROWKID_TRADE ~= true then	--- 屏蔽贸易
		trade_data.block = true
	end

	local crow = SpawnPrefab("monster_npc_crowkid_trader")
	crow.Ready = true
	crow:PushEvent("Set",{
		pt = pt,
		trade_data = trade_data,
	})
	crow:WatchWorldState("cycles",function()	-------- 第二天离开
		crow:DoTaskInTime(math.random(30),function()
			crow:PushEvent("flyaway")
		end)
	end)

	crow:WatchWorldState("isnight",function()	-------- 入夜后一段时间离开
		if TheWorld.state.isnight then
			crow:DoTaskInTime(math.random(120,300),function()
				crow:PushEvent("flyaway")
			end)
		end
	end)

	return crow
end

local function Create_Traders(inst)	
	local Points = inst.npc_base_lib:GetSurroundPoints({num = crows_num,range = 5})
	inst.__crow_traders = {}
	inst.__crow_trade_list = {}
	for i, pt in ipairs(Points) do
		-- SpawnPrefab("log").Transform:SetPosition(r_pt.x,0,r_pt.z)
		local trade_data = GetTradeData(inst,i)
		inst:DoTaskInTime(math.random(5),function()
			if not inst:IsValid() or inst.__crow_traders == nil then
				return
			end
			local r_pt = inst.npc_base_lib:GetSpawnPoint(pt,math.random(20)/10) or pt
			local crow = Create_single_crow(r_pt,trade_data)
			table.insert(inst.__crow_traders,crow)
		end)
	end

	inst:PushEvent("ring")
	inst:DoTaskInTime(2,function()
		inst:PushEvent("ring")
	end)
end



local function fn(inst)
	-----------------------------------------------------------
	inst:ListenForEvent("Create_Crows",function()
		Create_Traders(inst)		
	end)

	-----------------------------------------------------------
	-- ------ 每天创建新的商队
	inst:WatchWorldState("cycles",function()
		inst:DoTaskInTime(math.random(60, 80),function()
			inst:PushEvent("Create_Crows")
		end)
	end)
			
	-- inst:DoTaskInTime(3,function() Create_Traders(inst)	end) ----------------debugtest
	-----------------------------------------------------------
	inst:ListenForEvent("loot_prefab_spawned",function() --- 树被砍了
		if inst.__crow_traders then
			for k, crow in pairs(inst.__crow_traders) do
				if crow and crow:IsValid() then
					crow:DoTaskInTime(math.random(4),function()
						crow:PushEvent("flyaway")
					end)
				end
			end
			inst.__crow_traders = nil
		end
	end)   
	-----------------------------------------------------------
	---- 用来处理存档重进的时候 没有乌鸦的问题。新建的树不能有 商队
	
	inst:ListenForEvent("onbuilt",function()
		inst:AddTag("on_build_just_now")
	end)
	inst:DoTaskInTime(5,function()
		if inst:HasTag("on_build_just_now") then
			inst:RemoveTag("on_build_just_now")
			return
		end
		inst:PushEvent("Create_Crows")
	end)
	-----------------------------------------------------------
end

local function Fn()
    local Fx = Class()

    function Fx:Init(inst)
        local ret = fn(inst)
        return ret
    end


    return Fx
end

return Fn